//
//  TLST_movieCell.m
//  Travel_World
//
//  Created by lanou on 15/10/15.
//  Copyright © 2015年 TLS. All rights reserved.
//

#import "TLST_movieCell.h"
#import "TLST_movieModel.h"

@implementation TLST_movieCell
+ (instancetype)cellWithTableView:(UITableView *)tableView{
    static NSString *ID = @"movieCell";
    TLST_movieCell *cell = [tableView dequeueReusableCellWithIdentifier:ID];
    if (cell == nil) {
        cell = [[TLST_movieCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:ID];
    }
    return cell;
}
- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        self.ownerPicImageV = [[UIImageView alloc] init];
        [self.contentView addSubview:self.ownerPicImageV];
        self.ownerPicImageV.layer.cornerRadius = 25*WID;
        self.ownerPicImageV.layer.masksToBounds = YES;
        
        self.ownerNicknameL = [[UILabel alloc] init];
        self.ownerNicknameL.font = [UIFont systemFontOfSize:16];
        [self.contentView addSubview:self.ownerNicknameL];
        
        self.pubDateL = [[UILabel alloc] init];
        self.pubDateL.font = [UIFont systemFontOfSize:14];
        self.pubDateL.textColor = [UIColor grayColor];
        [self.contentView addSubview:self.pubDateL];
        
        self.titleL = [[UILabel alloc] init];
        self.titleL.numberOfLines = 0;
        self.titleL.font = [UIFont systemFontOfSize:16];
        [self.contentView addSubview:self.titleL];
        
        self.bigPicUrlImageV = [[UIImageView alloc] init];
        [self.contentView addSubview:self.bigPicUrlImageV];
        self.playButton = [UIButton buttonWithType:UIButtonTypeCustom];
        [self.playButton setImage:[UIImage imageNamed:@"iconfont-icon"] forState:UIControlStateNormal];
        self.bigPicUrlImageV.userInteractionEnabled = YES;
        [self.playButton addTarget:self action:@selector(playMovie:) forControlEvents:UIControlEventTouchUpInside];
        [self.bigPicUrlImageV addSubview:self.playButton];
        
        self.favorCountB = [UIButton buttonWithType:UIButtonTypeCustom];
        self.favorCountB.imageEdgeInsets = UIEdgeInsetsMake(0, 0, 0, 10);
        self.favorCountB.titleLabel.font = [UIFont systemFontOfSize:14];
        [self.favorCountB setTitleColor:[UIColor grayColor] forState:UIControlStateNormal];
        [self.favorCountB setImage:[UIImage imageNamed:@"iconfont-zan"] forState:UIControlStateNormal];
        [self.contentView addSubview:self.favorCountB];
        
        self.buryCountB = [UIButton buttonWithType:UIButtonTypeCustom];
        self.buryCountB.imageEdgeInsets = UIEdgeInsetsMake(0, 0, 0, 10);
        self.buryCountB.titleLabel.font = [UIFont systemFontOfSize:14];
        [self.buryCountB setTitleColor:[UIColor grayColor] forState:UIControlStateNormal];
        [self.buryCountB setImage:[UIImage imageNamed:@"iconfont-cai"] forState:UIControlStateNormal];
        [self.contentView addSubview:self.buryCountB];
        
        self.playTimesB = [UIButton buttonWithType:UIButtonTypeCustom];
        self.playTimesB.imageEdgeInsets = UIEdgeInsetsMake(0, 0, 0, 10);
        self.playTimesB.titleLabel.font = [UIFont systemFontOfSize:14];
        [self.playTimesB setTitleColor:[UIColor grayColor] forState:UIControlStateNormal];
        [self.playTimesB setImage:[UIImage imageNamed:@"iconfont-fenxiang"] forState:UIControlStateNormal];
        [self.contentView addSubview:self.playTimesB];
        
        self.commentCountB = [UIButton buttonWithType:UIButtonTypeCustom];
        self.commentCountB.imageEdgeInsets = UIEdgeInsetsMake(0, 0, 0, 10);
        self.commentCountB.titleLabel.font = [UIFont systemFontOfSize:14];
        [self.commentCountB setTitleColor:[UIColor grayColor] forState:UIControlStateNormal];
        [self.commentCountB setImage:[UIImage imageNamed:@"iconfont-pinglun"] forState:UIControlStateNormal];
        [self.contentView addSubview:self.commentCountB];
    }
    return self;
}
- (void)layoutSubviews{
    [super layoutSubviews];
    self.ownerPicImageV.frame = CGRectMake(10, 10, 50*WID, 50*WID);
    self.ownerNicknameL.frame = CGRectMake(50*WID+20, 10, WIDTH-50*WID-30, 25);
    self.pubDateL.frame = CGRectMake(50*WID+20, 35, WIDTH-50*WID-30, 25);
    self.titleL.frame = CGRectMake(10, 70, WIDTH-20, 30);
    
    self.bigPicUrlImageV.frame = CGRectMake(10, 110, WIDTH-20, WIDTH/2);
    self.playButton.frame = CGRectMake(WIDTH/2-30, (WIDTH-170)/2-30, 60, 60);
    
    self.favorCountB.frame = CGRectMake(0, CGRectGetMaxY(self.bigPicUrlImageV.frame)+10, WIDTH/4, 30);
    self.buryCountB.frame = CGRectMake(WIDTH/4, CGRectGetMaxY(self.bigPicUrlImageV.frame)+10, WIDTH/4, 30);
    self.playTimesB.frame = CGRectMake(WIDTH/2, CGRectGetMaxY(self.bigPicUrlImageV.frame)+10, WIDTH/4, 30);
    self.commentCountB.frame = CGRectMake(3*WIDTH/4, CGRectGetMaxY(self.bigPicUrlImageV.frame)+10, WIDTH/4, 30);
}
- (void)setMovieModel:(TLST_movieModel *)movieModel{
    if (_movieModel != movieModel) {
        _movieModel = movieModel;
    }
    [self.ownerPicImageV sd_setImageWithURL:[NSURL URLWithString:movieModel.ownerPic] placeholderImage:[UIImage imageNamed:@"WplaceImage.jpg"]];
    self.ownerNicknameL.text = movieModel.ownerNickname;
    self.pubDateL.text = movieModel.pubDate;
    self.titleL.text = movieModel.title;
    
    [self.bigPicUrlImageV sd_setImageWithURL:[NSURL URLWithString:movieModel.bigPicUrl] placeholderImage:[UIImage imageNamed:@"WplaceImage.jpg"]];
    [self.playButton setTitle:movieModel.outerGPlayerUrl forState:UIControlStateNormal];
    
    [self.favorCountB setTitle:[movieModel.favorCount description] forState:UIControlStateNormal];
    [self.buryCountB setTitle:[movieModel.buryCount description] forState:UIControlStateNormal];
    [self.playTimesB setTitle:[movieModel.playTimes description] forState:UIControlStateNormal];
    [self.commentCountB setTitle:[movieModel.commentCount description] forState:UIControlStateNormal];

}
- (void)playMovie:(UIButton *)button {
    if ([self.delegate respondsToSelector:@selector(moviePlayWithUrl:)]) {
        [self.delegate moviePlayWithUrl:button.currentTitle];
        NSLog(@"%@",button.currentTitle);
    }
}

- (void)awakeFromNib {
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
